<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .time {
            padding: 0;
            margin: 0;
            height: 30px;
            line-height: 30px;
            text-align: center;
            box-sizing: border-box;
        }
    </style>
</head>

<body>
    <p class="time"></p>
</body>

<!--随机数-------------------------------------------------------------------->
<script type="text/html">
    //
    var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];

    function getColor() {
    var color = "#";
    for (var x = 0; x < 6; x++)
    color += arr[Math.floor(Math.random() * 16)];
    return color;
    }

    for (var i = 0; i < 50; i++)
    <!--        document.write("<div style='background:" + getColor() + "'>1</div>");-->
</script>

<!--数组反转------------------------------------------------------------------->
<script type="text/html">
    //
    function fanzhuan(arr) {
    var m = arr.length - 1;
    var n = Math.ceil(m / 2);
    var x;
    for (var i = 0; i < n; i++) {
    x = arr[i];
    arr[i] = arr[m - i];
    arr[m - i] = x;
    }
    return arr;
    }

    var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    console.log(arr);
    console.log(fanzhuan(arr));
    console.log(arr.reverse());
</script>

<!--计算时间差----------------------------------------------------------------->
<script>
    // type="text/html"
    function timeDifference(date1, date2, dom) {
        let difs = Math.floor(Math.abs(date1.getTime() - date2.getTime()) / 1000);
        let month = Math.floor(difs / (60 * 60 * 24 * 30));
        let day = Math.floor((difs -= month * 60 * 60 * 24 * 30) / (60 * 60 * 24));
        let hour = Math.floor((difs -= day * 60 * 60 * 24) / (60 * 60));
        let minute = Math.floor((difs -= hour * 60 * 60) / 60);
        dom.innerHTML = "距国庆节还有" + month + "个月，" + day + "天，" + hour + "个小时，" + minute + "分钟，" + difs % 60 + "秒";
    }

    window.onload = function () {
        let future = new Date("2019-10-1 00:00:00");
        let p = document.querySelector('.time');
        setInterval(function () {
            timeDifference(future, new Date(), p);
        }, 1000)
    }
</script>

</html>